﻿@model List<HZYProject.Domain.Course>
@{ var list = ViewBag.Names as List<HZYProject.Domain.TestPaper>;}

<div class="layer-edit" style="padding:10px">
    <form id="formAdd" class="layui-form" action="" onsubmit="return false">
        <div class="layui-inline">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input type="text" name="StartTime" id="date" lay-verify="date" placeholder="请输入开始时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">章节名称</label>
            <div class="layui-input-inline">
                <input type="text" name="Title" required lay-verify="required" placeholder="请输入章节名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属课程</label>
            <div class="layui-input-inline">
                <select id="CourseID" name="CourseID" lay-search="" lay-verify="required">
                    <option value="">--全部--</option>
                    @{
                        foreach (var item in Model)
                        {
                            <option value="@item.CourseID">@item.Title</option>
                        }
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属试卷</label>
            <div class="layui-input-inline">
                <select id="TestPaperID" name="TestPaperID" lay-search="" lay-verify="required">
                    <option value="">--全部--</option>
                    @{
                        foreach (var item in list)
                        {
                            <option value="@item.TestPaperID">@item.Title</option>
                        }
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">时长（分钟）</label>
            <div class="layui-input-inline">
                <input type="text" name="Duration" required lay-verify="required" placeholder="请输入时长（分钟）" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="pear-btn pear-btn-primary pear-btn-sm" lay-submit lay-filter="formDemo">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
</div>
@section script{
    <script>
        layui.use(['form', 'jquery', 'laydate'], function () {
            var form = layui.form;
            let $ = layui.jquery;
            let laydate = layui.laydate;

            //日期
            laydate.render({
                elem: '#date'
            });
            form.on('submit(formDemo)', function (data) {
                var str = $("#formAdd").serialize();
                $.post("/Exam/add", str, function (res) {
                    if (res.success) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    }
                    else
                        layer.msg("添加失败：" + res.msg, {
                            icon: 2,
                            time: 1000
                        });
                }, "json");
                return false;
            });
        });

    </script>
}